We consider the $p$-adic random walk model in a potential, which can be viewed as a generalization of $p$-adic random walk models used for description of protein conformational dynamics. This model is based on the Kolmogorov--Feller equations for the distribution function defined on the field of $p$-adic numbers in which the probability of transitions per unit time depends on ultrametric distance between the transition points as well as on function of potential violating the spatial homogeneity of a random process. This equation, which will be called the equation of $p$-adic random walk in a potential, is equivalent to the equation of $p$-adic random walk with modified measure and reaction source. With a special choice of a power-law potential the last equation is shown to have an exact analytic solution. We find the analytic solution of the Cauchy problem for such equation with an initial condition, whose support lies in the ring of integer $p$-adic numbers. We also examine the asymptotic behaviour of the distribution function for large times. It is shown that in the limit $t\rightarrow\infty$ the distribution function tends to the equilibrium solution according to the law, which is bounded from above and below by power laws with the same exponent. Our principal conclusion is that the introduction of a potential in the ultrametric model of conformational dynamics of protein conserves the power-law behaviour of relaxation curves for large times.